{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Project: AFEM for the Heat Equation\n",
    "\n",
    "The purpose of this project is to implement explict and implicit\n",
    "numerical methods for solving the parabolic equation. The example is the heat equation \n",
    "\n",
    "$$ u_t -\\Delta u  = f \\quad \\text{ with }u |_{\\partial \\Omega} = g, u(\\cdot,0) = u_0.$$\n",
    "\n",
    "We consider a 2-d problem on the unit square $\\Omega = (0,1)^2$ with the\n",
    "exact solution\n",
    "\n",
    "$$u(x,t) = \\beta (t)\\, \\exp(-[(x-t+0.5)^2+(y-t+0.5)^2]/0.04),$$ \n",
    "\n",
    "with $$\\beta (t) = 0.1\\,(1-\\exp(-10^2(t-0.5)^2)).$$\n",
    "\n",
    "Adaptive FEM is further applied to capture the singularity of the solution."
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Step 1: Forward Euler, Backward Euler, and Crack-Nicolson methods\n",
    "\n",
    "- Given a mesh, construct the stiffness matrix `A` for the Laplace operator and the mass matrix `M` for the $L^2$-inner product.\n",
    "\n",
    "- Given a time step size `dt`, final time `T`, code a for loop over time to involve the solution by either forward, backward Euler or Crack-Nicolson methods.\n",
    "\n",
    "> Please do not store the approximation at all time steps. Instead only the solution in the previous step `uold` and the current step `u` is needed.\n",
    "\n",
    "- For implicit methods, use direct solver `A\\b` or multigrid solvers to solve the linear system `Au=b`. For meshes generated in `ifem`, `mg(A,b,elem)` is faster than `amg(A,b)`."
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Step 2: Check the Convergence\n",
    "\n",
    "- Check the convergence rate in time and space. Use the exact solution to get the nodal interpolant `uI` and compute the H1 norm of the error using matrix `A` and the L2 norm using matrix `M`.\n",
    "\n",
    "- To check the convergence rate in time, fix a small mesh size `h` in space\n",
    " and let `dt` vary and vice verse for convergence in space."
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Step 3: Visulization\n",
    "\n",
    "- Use `showsolution(node,elem,u)` to plot the solution and together with `pause(0.01)` to get an animation. Use `axis` to fix the axis scaling.\n",
    "\n",
    "> For small time step, do not plot the solution at every time step. Instead plot every 10 or 100 steps.\n",
    "\n",
    "- You can save the plot into a movie. Read `doc getframe` for an example."
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Step 4: Adaptive Finite Element Methods\n",
    "\n",
    "- Run 2D examples: `Lshape` in iFEM and read the code to learn the usage of AFEM; see also [Adaptive Finite Element Methods](../afem/afemdoc.html)\n",
    "\n",
    "- In one time step involution, repeat the refinement and coarsen several steps to get a better approximation of the solution. You can control the max iteration steps for AFEM or the maximal number of elements. \n",
    "\n",
    "- Use `eta = estimaterecovery(node,elem,u)` instead of residual type error estimators.\n",
    "\n",
    "- Use `nodeinterpolate` and `eleminterpolate` to interpolate function between different meshes.\n",
    "\n",
    "- Check the convergence rate for AFEM.\n",
    "\n",
    "- Make animation for meshes and solutions."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Matlab",
   "language": "matlab",
   "name": "matlab"
  },
  "language_info": {
   "codemirror_mode": "octave",
   "file_extension": ".m",
   "help_links": [
    {
     "text": "MetaKernel Magics",
     "url": "https://github.com/calysto/metakernel/blob/master/metakernel/magics/README.md"
    }
   ],
   "mimetype": "text/x-matlab",
   "name": "matlab",
   "version": "0.14.3"
  },
  "toc": {
   "colors": {
    "hover_highlight": "#DAA520",
    "navigate_num": "#000000",
    "navigate_text": "#333333",
    "running_highlight": "#FF0000",
    "selected_highlight": "#FFD700",
    "sidebar_border": "#EEEEEE",
    "wrapper_background": "#FFFFFF"
   },
   "moveMenuLeft": true,
   "nav_menu": {
    "height": "102px",
    "width": "252px"
   },
   "navigate_menu": true,
   "number_sections": true,
   "sideBar": true,
   "threshold": 4,
   "toc_cell": false,
   "toc_section_display": "block",
   "toc_window_display": false,
   "widenNotebook": false
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
